<?php
namespace app\api\controller;


use app\api\model\Category;
use app\api\model\Province;
use app\api\model\Slide;
use app\api\model\Goods;
use app\BaseController;

class SystemController extends BaseController
{
    // 首页数据
    public function indexData(Goods $goods)
    {
        $data = [
            'topAd'=>[
                [
                    'href'=>'http://www.baidu.com',
                    'imgSrc'=>'https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/d8a6d6d37904e22c72130e3e4ec79b41.jpg'
                ],
                [
                    'href'=>'http://www.baidu.com',
                    'imgSrc'=>'https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/fce474f4024b96545959ccd45b7e50f3.jpg'
                ],
                [
                    'href'=>'http://www.baidu.com',
                    'imgSrc'=>'https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/9f18ac756fa2cedb16ea429b9c0001af.png?w=632&h=340'
                ],
            ],
            // 手机
            'mobile'=>[
                'imgSrc'=>'https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/c583f2edc613f1be20fa415910b13ce3.jpg?thumb=1&w=234&h=614&f=webp&q=90',
                'goods'=>$goods->getCategoryRecommend(2,8)
            ],

        ];
        return $this->returnJson(SUCCESS_MESSAGE,$data);
    }
	// 首页推荐商品
	public function recommend(Goods $goods)
	{
		$data =[
			'crazy'=>$goods->getRecommendGoods('is_crazy'),
			'hot'=>$goods->getRecommendGoods('is_hot'),
			'rec'=>$goods->getRecommendGoods('is_rec'),
			'new'=>$goods->getRecommendGoods('is_new'),
			'guess'=>$goods->getRecommendGoods('guess')
		];
		return $this->returnJson(SUCCESS_MESSAGE,$data,count($data));
	}
	// 首页幻灯
	public function homeSlide(Slide $model)
	{
		$slide = $model->order('order desc')->limit(5)->select();
		return $this->returnJson(SUCCESS_MESSAGE,$slide,count($slide)); 
	}
	// 获取分类
	public function category(Category $model)
	{
		$category = getTree($model->select()->toArray());
		return $this->returnJson('ok',$category,count($category));
	}

	// 获取指定城市的所有的下级
	public function province(Province $model)
	{
		$parentId = $this->request->param('parentId',0);

		$province = $model->where('parent_id',$parentId);
		
		return $this->returnJson('ok',$province->select(),$province->count());
	}
}